-
Notifications
You must be signed in to change notification settings - Fork 244
Issue #1300 - nb_inventory injecting a variable as api_endpoint #1301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: devel
Are you sure you want to change the base?
Conversation
Fixes issue-netbox-community#1300 allows api_endpoint to be a variable and string
The netbox inventory plugin already supports the environment variable Can you shed some light on why this change is required when we already have this environment variable? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nb_inventory
plugin already supports an environment variable, please see the existing documentation.
There has been discussion about the Ansible modules being able to use the environment variable, which both your issue and #1363 discusses, but this code only touches the nb_inventory
plugin which already has support.
This would really help. Setting an environment variable is a primitive solution if you work with several people in several environments. Being able to specify the netbox_api somewhere else would solve a lot of hassle for me. |
Another use case for templar here is lookup plugins pulling the API endpoint value from a secrets manager or parameter store (community.general.onepassword, amazon.aws.ssm_parameter, community.general.consul_kv, etc.). I'd like to be able to do: ---
plugin: netbox.netbox.nb_inventory
# api_endpoint: https://my.netbox.fqdn
api_endpoint: "{{ lookup('community.general.onepassword', 'My NetBox Item', vault='My Vault', section='API', field='endpoint') }}"
token: "{{ lookup('community.general.onepassword', 'My NetBox Item', vault='My Vault', section='API', field='ro-token') }}" |
@sc68cal I believe why I did this was as @Woefdram said, our organization viewed setting the environment variable as a more primitive solution. Also for the reasonings he mentioned we have three different environments. We create one inventory file(for each inventory) for all three environments. We personally use ansible controller and use credentials within ansible controller, this allows us to statically set the token and URL for each of our environments. This allows us the security of keeping the token encrypted as well. Along those lines it is also easier when the token expires as it's a quick on the fly change to update the token. |
Fixes issue-#1300
allows api_endpoint to be a variable and string
Related Issue
#1300
New Behavior
calls the templar.template module to transform the api_endpoint if referenced as a variable e.g: "{{ fake_var }}"
Contrast to Current Behavior
fake_var: "https://netbox.test.domain.com"
Current behavior for a inventory file is referencing
api_endpoint: "{{ fake_var }}"
for the above example you would receive an error to the affect of
[WARNING]: * Failed to parse <location of your netbox plugin> with auto plugin: unknown url type: "{{ fake_var }}/api/status"
this solves that issue and the result is no error and we can see
Fetching: https://netbox.test.domain.com/api/status
Discussion: Benefits and Drawbacks
Changes to the Documentation
N/A
Proposed Release Note Entry
netbox.nb_inventory: api_endpoint option can now take variable calls E.G:
api_endpoint: "{{ netbox_url }}"
Double Check
devel
branch.